package com.oolatina;

import com.oolatina.R;
import com.oolatina.R.drawable;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.util.Log;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;

public class SCItunesPartner implements OnClickListener
{
	int _width;
	int _height;
	int _x;
	int _y;
	Context _context;
	int ScreenWidth;
	int ScreenHeight;
	Button nButton;
	String _url;
	
	@SuppressLint("NewApi")
	public void init(ViewGroup layout,Context thisContext)
	{
		_width = 0;
		_height = 0;
		_x = 0;
		_y = 0;
		_context = thisContext;
		
		WindowManager wm = (WindowManager) thisContext.getSystemService(Context.WINDOW_SERVICE);
	    Display display = wm.getDefaultDisplay();
	    ScreenWidth = display.getWidth();
	    ScreenHeight = display.getHeight();
		 
	    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ScreenWidth, 60);
	    
	    nButton = new Button(thisContext);
//	    layoutParams.setMargins(_x,_y,0,0);
	    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        nButton.setLayoutParams(layoutParams);
        layout.addView(nButton);
        // Event onClick
        nButton.setOnClickListener(this);
        nButton.setBackgroundResource(R.drawable.ituneslink);
        
	}
	
	public void rightBottom(int imageResourceId)
	{
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
				_width,_height);
		layoutParams.addRule(RelativeLayout.ALIGN_RIGHT, imageResourceId);
		layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, imageResourceId);
        nButton.setLayoutParams(layoutParams);
	}
	
	public void SetPosition(int x,int y)
	{
		_x = x;
		_y = y;
		
		FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
				_width,_height);
        layoutParams.setMargins(_x,_y,0,0);
        nButton.setLayoutParams(layoutParams);
	}
	
	public void SetSize(int width,int height)
	{
		_width = width;
		_height = height;
		
		FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
				_width,_height);
        layoutParams.setMargins(_x,_y,0,0);
        nButton.setLayoutParams(layoutParams);
	}
	
	public void SetPourcentSize(int width, int height)
	{
		float radioWidth = (float)ScreenWidth/100;
    	float radioHeight = (float)ScreenHeight/100;
    	_width = (int)(radioWidth*width);
    	_height = (int)(radioHeight*height);
		
		FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
				_width,_height);
        layoutParams.setMargins(_x,_y,0,0);
        nButton.setLayoutParams(layoutParams);
	}
	
	public int SetPourcentWidth(int width)
	{
		float radioWidth = (float)ScreenWidth/100;
		_width = (int)(radioWidth*width);
		
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
				_width,_height);
//        layoutParams.setMargins(_x,_y,0,0);
        nButton.setLayoutParams(layoutParams);
        return _width;
	}
	
	public int SetPourcentHeight(int height)
	{
		float radioHeight = (float)ScreenHeight/100;
		_height = (int)(radioHeight*height);
		
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
				_width,_height);
//        layoutParams.setMargins(_x,_y,0,0);
        nButton.setLayoutParams(layoutParams);
        return _height;
	}
	
	public void SetURL(String url)
	{
		_url = url;
	}
	
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	public void SetAlpha(float al)
	{
		nButton.setAlpha(al);
	}
	
	@Override
    public void onClick(View v) 
	{
		Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(_url));
		_context.startActivity(browserIntent);
    }
}
